<template>
	<view class="content" :style="'background:#f7f7f7;'">
		<view class="create-view" :style="'background:#FFFFFF;'">
			<view class="create-red">
				<view class="" style="width: 100%;height: 100%;display: flex;align-items: center;justify-content: center;" :style="{background:'#f7f7f7;'}">
					<image class="red-image" :src="top_iamge" mode="heightFix"></image>
				</view>
				<view class="change-image-red font28" :style="'color:#FFFFFF;'" @click="changeTitleImage">
					<text>更换图片</text>
				</view>
			</view>
			<block v-for="(item, index) in create_luttery.goods" :key="index" v-if="page_type == 2">
				<view class="red-item-money" :style="'border-bottom:2rpx solid #EBEBEB;'">
					<image v-if="index>0" @click="deleteIndexRedMoney(index,item)" class="delete-image" src="../../../static/delete_red.png" mode=""></image>
					<view class="item-info">
						<view class="all-red-number-money" :style="'border-bottom:2rpx solid #EBEBEB;'">
							<view class="left-title">
								<image class="left-icon" v-if="item.type == 3" src="../../../static/Spell_icon.png" mode=""></image>
								<image class="left-icon" v-if="item.type == 2" src="../../../static/universal_icon.png" mode=""></image>
								<text class="font30 text-all" :style="'color:#111111;'">总金额</text>
								<text class="font24" :style="'color:#CF9957;'" v-if="item.type == 3" @click="changeMoneyType(index,2)">改为普通红包</text>
								<text class="font24" :style="'color:#CF9957;'" v-if="item.type == 2" @click="changeMoneyType(index,3)">改为拼手气红包</text>
							</view>
							<view class="input-class" @click="getRedIndex(index)">
								<input style="text-align: right;" class="input-text" v-model="item.money" type="text" :placeholder-style="'color:#AEAEAE;text-align:right;'" placeholder="总金额" />
								<text class="font30" :style="'color:#111111;'">元</text>
							</view>
						</view>
						<view class="all-red-number-money" :style="'border-bottom:2rpx solid #EBEBEB;'">
							<view class="left-title">
								<text class="font30 text-all" :style="'color:#111111;'">红包个数</text>
							</view>
							<view class="input-class" @click="getRedIndex(index)">
								<input class="input-text" v-model="item.num" type="text" :placeholder-style="'color:#AEAEAE;text-align:right;'" placeholder="数量" />
								<text class="font30" :style="'color:#111111;'">个</text>
							</view>
						</view>
						<!-- <view class="all-red-number-money" :style="'border-bottom:2rpx solid #EBEBEB;'" v-if="create_luttery.prize.open_type == 3">
							<view class="left-title">
								<text class="font30 text-all" :style="'color:#111111;'">中奖概率</text>
							</view>
							<view class="input-class">
								<input class="input-text" v-model="item.probability" type="text" :placeholder-style="'color:#AEAEAE;text-align:right;'" placeholder="中奖概率" />
								<text class="font30" :style="'color:#111111;'">%</text>
							</view>
						</view> -->
					</view>
				</view>
			</block>
			<view class="add-red-money" :style="'color:#E9564F;'" @click="addRedMoneyNumber" v-if="page_type == 2">
				+添加红包
			</view>
		</view>
		<block v-for="(item, index) in create_luttery.goods" :key="index">
			<view class="create-view-page2" :style="'background:#FFFFFF;'" v-if="page_type == 1">
				<view class="create-red">
					<view class="" style="width: 100%;height: 100%;display: flex;align-items: center;justify-content: center;" :style="{background:'#f7f7f7;'}">
						<image class="red-image" :src="gift_image[index]" mode="heightFix"></image>
					</view>
					<view class="change-image-red font28" :style="'color:#FFFFFF;'" @click="changeGiftImage(index)">
						<text>更换图片</text>
					</view>
				</view>
				<view class="red-item-money" :style="{'border-bottom':'2rpx solid #EBEBEB;'}">
					<view class="item-info">
						<view class="all-red-number-money" :style="'border-bottom:2rpx solid #EBEBEB;'">
							<view class="left-title">
								<text class="font30 text-all" :style="'color:#111111;'">{{index+1}}等奖名称</text>
							</view>
							<view class="input-class" @click="getRedIndex(index)">
								<input class="input-text-page2" v-model="item.name" type="text" :placeholder-style="'color:#AEAEAE;'" placeholder="请输入奖品名称" />
							</view>
						</view>
						<view class="all-red-number-money" :style="'border-bottom:2rpx solid #EBEBEB;'"  @click="goToAddKey(index)">
							<view class="left-title">
								<text class="font30 text-all" :style="'color:#111111;'">奖品码设置</text>
							</view>
							<view class="input-class">
								<text class="input-text-page21" :style="'color:#AEAEAE;'" v-if="item.code==''">请设置</text>
								<text class="input-text-page21" :style="'color:#AEAEAE;'" v-if="item.code!=''">已设置</text>
								<image class="page2-image" src="../../../static/neck-bload.png"></image>
							</view>
						</view>
						<!-- <view class="all-red-number-money" v-if="create_luttery.prize.open_type == 3">
							<view class="left-title">
								<text class="font30 text-all" :style="'color:#111111;'">中奖概率</text>
							</view>
							<view class="input-class">
								<input class="input-text" v-model="item.probability" type="text" :placeholder-style="'color:#AEAEAE;text-align:right;'" placeholder="中奖概率" />
								<text class="font30" :style="'color:#111111;'">%</text>
							</view>
						</view> -->
					</view>
				</view>
				<text @click="addGiftClick" class="add-red-money" style="margin-bottom: 30rpx;" v-if="index == (create_luttery.goods.length-1)" :style="'color:#E9564F;'" >+添加{{number_chanese}}等奖</text>
			</view>
		</block>
		<view class="create-view" :style="'background:#FFFFFF;'">
			<text class="font34 fontw500" :style="'width:100%;color:#111111;'">抽奖说明</text>
			<textarea class="textarea-class" v-model="create_luttery.prize.desc" :placeholder-style="'color:#AEAEAE;'" placeholder="非必填，请输入文字内容" />
		</view>
		<view class="create-view" :style="'background:#FFFFFF;'" style="padding-bottom: 0;">
			<view class="join-index">
				<view class="top-title" :style="'border-bottom:2rpx solid #EBEBEB;'">
					<text class="font34 fontw500" :style="'width:100%;color:#111111;'">开奖设置</text>
				</view>
				<view class="title-item" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="$refs.openConditionPopup.open()">
					<text class="font30" :style="'color:#111111;'">开奖条件</text>
					<view class="item-left">
						<text class="font28" v-if="create_luttery.prize.open_type == 1" :style="'color:#AEAEAE;'">按时间自动开奖</text>
						<text class="font28" v-if="create_luttery.prize.open_type == 2" :style="'color:#AEAEAE;'">按人数开奖</text>
						<text class="font28" v-if="create_luttery.prize.open_type == 3" :style="'color:#AEAEAE;'">即开即中</text>
						<image class="next-bload" src="../../../static/neck-bload.png" mode=""></image>
					</view>
				</view>
				<view class="title-item" @click="$refs.upickerPopup.open()">
					<text class="font30" :style="'color:#111111;'">截止时间</text>
					<view class="item-left">
						<view class="font28" :style="'color:#AEAEAE;'">{{create_luttery.prize.open_time}}</view>
						<image class="next-bload" src="../../../static/neck-bload.png" mode=""></image>
					</view>
				</view>
				<view class="title-item">
					<text class="font30" :style="'color:#111111;'">开奖人数</text>
					<view class="item-left">
						<input style="text-align: right;" class="input-text" type="text" :placeholder-style="'color:#AEAEAE;text-align:right;'" placeholder="人数" v-model="create_luttery.prize.open_num" />
						<image class="next-bload" src="../../../static/neck-bload.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view class="create-view" :style="'background:#FFFFFF;'" style="padding-bottom: 0;">
			<view class="join-index">
				<view class="top-title" :style="'border-bottom:2rpx solid #EBEBEB;'">
					<text class="font34 fontw500" :style="'width:100%;color:#111111;'">抽奖设置</text>
				</view>
				<view class="title-item" :style="'border-bottom:2rpx solid #EBEBEB;'">
					<text class="font30" :style="'color:#111111;'">抽奖标题</text>
					<view class="item-left">
						<input style="text-align: right;" class="input-text" type="text" :placeholder-style="'color:#AEAEAE;text-align:right;'" placeholder="请输入标题" v-model="create_luttery.prize.name" />
						<image class="next-bload" src="../../../static/neck-bload.png" mode=""></image>
					</view>
				</view>
				<view class="title-item" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="$refs.openCategoryPopup.open()">
					<text class="font30" :style="'color:#111111;'">分类设置</text>
					<view class="item-left">
						<text class="font28" :style="'color:#AEAEAE;'">{{category_name}}</text>
						<image class="next-bload" src="../../../static/neck-bload.png" mode=""></image>
					</view>
				</view>
				<!-- <view class="title-item" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="$refs.opentabPopup.open()">
					<text class="font30" :style="'color:#111111;'">标签设置</text>
					<view class="item-left">
						<text class="font28" :style="'color:#AEAEAE;'">{{tab_name}}</text>
						<image class="next-bload" src="../../../static/neck-bload.png" mode=""></image>
					</view>
				</view> -->
			</view>
		</view>
		<view class="create-view" :style="'background:#FFFFFF;'" style="padding-bottom: 0;">
			<view class="join-index" :style="'height:'+(join_show?'auto;':'92rpx;')">
				<view class="top-title" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="join_show = !join_show">
					<text class="font34 fontw500" :style="'width:100%;color:#111111;'">参与条件</text>
					<image class="show-more" :class="!join_show?'class-show-0':'class-show-180'" src="../../../static/showmoer.png" mode=""></image>
				</view>
				<view class="title-item" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="$refs.openSexPopup.open()">
					<text class="font30" :style="'color:#111111;'">限定性别</text>
					<view class="item-left">
						<text class="font28" v-if="sex == 1" :style="'color:#AEAEAE;'">男</text>
						<text class="font28" v-if="sex == 2" :style="'color:#AEAEAE;'">女</text>
						<text class="font28" v-if="sex == 0 || sex == 3" :style="'color:#AEAEAE;'">不限</text>
						<image class="next-bload" src="../../../static/neck-bload.png" mode=""></image>
					</view>
				</view>
				<!-- <view class="title-item" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="$refs.openUserCardPopup.open()">
					<text class="font30" :style="'color:#111111;'">实名抽奖</text>
					<view class="item-left">
						<text class="font28" v-if="is_usercard == 1" :style="'color:#AEAEAE;'">是</text>
						<text class="font28" v-if="is_usercard == 2" :style="'color:#AEAEAE;'">否</text>
						<text class="font28" v-if="is_usercard == 3" :style="'color:#AEAEAE;'">未设置</text>
						<image class="next-bload" src="../../../static/neck-bload.png" mode=""></image>
					</view>
				</view> -->
				<view class="title-item" @click="goToSetKey">
					<text class="font30" :style="'color:#111111;'">口令抽奖</text>
					<view class="item-left">
						<text v-if="luttery_key!=''" class="font28" :style="'color:#AEAEAE;'">{{luttery_key}}</text>
						<text v-else class="font28" :style="'color:#AEAEAE;'">未设置</text>
						<image class="next-bload" src="../../../static/neck-bload.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view class="create-view" :style="'background:#FFFFFF;'" style="padding-bottom: 0;" @click="goToAddFans">
			<view class="title-item" style="padding-top: 0;">
				<text class="font34 fontw500" :style="'color:#111111;'">快捷加粉</text>
				<view class="item-left">
					<text class="font28" :style="'color:#AEAEAE;'">点击设置</text>
					<image class="next-bload" src="../../../static/neck-bload.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="create-view" :style="'background:#FFFFFF;'">
			<text class="font34 fontw500" :style="'width:100%;color:#111111;'">图文介绍</text>
			<textarea class="textarea-class-rule" v-model="create_luttery.prize.content" :placeholder-style="'color:##AEAEAE;'" placeholder="请输入文字内容" />
			<block v-for="(item, index) in prize_image" :key="index">
				<image v-if="prize_image.length!=0" :src="item" mode="heightFix"></image>
			</block>
			<view class="add-image" @click="uploadqucodefunction">
				<view class="addimage">
					<image class="upload-image" src="../../../static/add_image_icon.png" mode=""></image>
					<text class="font28" :style="'color:#111111;'">添加图片</text>
				</view>
			</view>
		</view>
		<text class="bottom-text font28" :style="'color:#AEAEAE;'" v-if="page_type == 2">需收取红包总金额{{luttery_config.prizedraw_charges}}%的手续费</text>
		<view class="bottom-btn" :style="'background:#E9564F;'" @click="beforeNowCreate(1)" v-if="page_type == 2">
			<text :style="'color:#FFFFFF;'">保存修改</text>
		</view>
		<view class="bottom-btn" :style="'background:#E9564F;'" @click="beforeNowCreate(1)" v-if="page_type == 1">
			<text :style="'color:#FFFFFF;'">保存修改</text>
		</view>
		<uni-popup ref="openUserCardPopup" type="bottom">
			<view class="publicpopup" >
				<view class="condition-list" :style="'background:#FFFFFF;'">
					<view class="item1" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="changeUserCardStatus(1)">
						<text>是</text>
					</view>
					<view class="item1" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="changeUserCardStatus(2)">
						<text>否</text>
					</view>
				</view>
				<view class="" style="width: 750rpx;height: 20rpx;" :style="'background:#EBEBEB;'"></view>
				<view class="condition-item2" :style="'background:#FFFFFF;'" @click="changeUserCardStatus(3)">
					<text>取消</text>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="openConditionPopup" type="bottom">
			<view class="publicpopup" >
				<view class="condition-list" :style="'background:#FFFFFF;'">
					<view class="item1" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="changeCondition(1)">
						<text>按时间自动开奖</text>
					</view>
					<view class="item1" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="changeCondition(2)">
						<text>按人数开奖</text>
					</view>
					<view class="item1" @click="changeCondition(3)">
						<text>即开即中</text>
					</view>
				</view>
				<view class="" style="width: 750rpx;height: 20rpx;" :style="'background:#EBEBEB;'"></view>
				<view class="condition-item2" :style="'background:#FFFFFF;'" @click="changeCondition(3)">
					<text>取消</text>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="openSexPopup" type="bottom">
			<view class="publicpopup" >
				<view class="condition-list" :style="'background:#FFFFFF;'">
					<view class="item1" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="changeSex(0)">
						<text>不限</text>
					</view>
					<view class="item1" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="changeSex(1)">
						<text>男</text>
					</view>
					<view class="item1" @click="changeSex(2)">
						<text>女</text>
					</view>
				</view>
				<view class="" style="width: 750rpx;height: 20rpx;" :style="'background:#EBEBEB;'"></view>
				<view class="condition-item2" :style="'background:#FFFFFF;'" @click="changeSex(3)">
					<text>取消</text>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="openCategoryPopup" type="bottom">
			<view class="publicpopup" >
				<view class="condition-list" :style="'background:#FFFFFF;'">
					<block v-for="(item, index) in category_list" :key="index">
						<view class="item1" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="changeCategory(item.id,item.name)">
							<text>{{item.name}}</text>
						</view>
					</block>
				</view>
				<view class="" style="width: 750rpx;height: 20rpx;" :style="'background:#EBEBEB;'"></view>
				<view class="condition-item2" :style="'background:#FFFFFF;'" @click="$refs.openCategoryPopup.close()">
					<text>取消</text>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="opentabPopup" type="bottom">
			<view class="publicpopup" >
				<view class="condition-list" :style="'background:#FFFFFF;'">
					<block v-for="(item, index) in tab_list" :key="index">
						<view class="item1" :style="'border-bottom:2rpx solid #EBEBEB;'" @click="changetab(item.id,item.name)">
							<text>{{item.name}}</text>
						</view>
					</block>
				</view>
				<view class="" style="width: 750rpx;height: 20rpx;" :style="'background:#EBEBEB;'"></view>
				<view class="condition-item2" :style="'background:#FFFFFF;'" @click="$refs.opentabPopup.close()">
					<text>取消</text>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="upickerPopup" type="bottom">
			<view class="publicpopup" >
				<upicker :default-time="default_time" @cancel="$refs.upickerPopup.close()" @confirm="changeTime" class="font28" style="width: 100%;" mode="time" :params="params"></upicker>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	var util = require('@/js/util.js')
	import upicker from "@/uview-ui/components/u-picker/u-picker.vue"
	export default {
		components:{
			upicker
		},
		data() {
			return {
				join_show:false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
				gift_image:[],
				red_index:0,
				text_rule:'',
				upload_image:'',
				conditions:3,
				luttery_key:'',
				page_type:1,
				add_gift_list:[
					{
						id:1,
						image:'',
						zn_chanese:"一",
						gift_name:'',
						gift_key:''
					},
				],
				gift_list_length:1,
				number_chanese:'二',
				sex:0,
				is_usercard:3,
				open_luttery_usernum:'',
				date:'点击设置',
				category_list:'',
				category_id:'',
				category_name:'未设置',
				tab_list:'',
				tab_id:'',
				tab_name:'未设置',
				luttery_config:'',
				default_time:"",
				prize_image:[],
				create_luttery:{
					status:0, //0保存 1发布（红包活动需要先保存，支付才能发布）
					prize:{
						type_id:0,//分类id
						tag_id:0,//标签id
						type:1,//1抽奖码 2红包
						name:"",//标题
						desc:'',//说明
						cover:'',//封面图
						robot_total:0,//机器人总数
						single_robot_min:0,//单次最少增加N个机器人
						single_robot_max:0,//单次最多增加N个机器人
						open_type:3,//开奖类型(1指定时间 2指定人数 3即开即中)
						open_time:'',//开奖时间（open_type 1、3的时候选择结束时间 ）
						open_num:0,//开奖人数（open_type 2的时候选择结束时间 ）
						condition_sex:0,//性别限制(0不限 1男 2女)
						condition_token:'',//抽奖口令
						content:'',//图文内容的内容
						images:[],//图片数组 示例：[‘1.png’,’2.jpg’]
						diversion_type:1,//引流类型(1微信号 2公众号 3小程序 4微信群)
						diversion_name:'',//引流名称
						diversion_image:'',//引流图片
						diversion_appid:'',//引流小程序Appid 当diversion_type=3时可以传这个
						diversion_path:'',//引流小程序路径 当diversion_type=3时可以传这个
					},
					goods:[
						{
							id:'',
							type:2,//1抽奖码 2普通红包 3手气红包
							name:"",//奖品名称 （红包奖品不需要填这个）
							image:'',//奖品图片 （红包奖品不需要填这个）
							code:'',//奖品码（一行一个）（红包奖品不需要填这个）
							money:'',//红包金额
							num:'',//红包数量
							probability:0,//中奖概率（即开即中的时候 需要设置每个奖项的中奖概率）
						},
					]
				},
				open_time:'未设置',
				top_iamge:"",
				luttery_id:'',
				edit_type:'',
				goods_id:''
			};
		},
		onLoad(e) {
			this.page_type = e.type
			this.luttery_id = e.id
			this.edit_type = e.editType
			this.getLutteryInfo()
			this.create_luttery.goods[0].type = this.page_type
			this.luttery_config = uni.getStorageSync("luttery_config")
		},
		onHide() {
			uni.setStorageSync("create_luttery",this.create_luttery)
			// this.$store.commit("saveGiftCode","")
			console.log("onhide")
		},
		onUnload() {
			console.log("onunload")
			this.$store.commit("saveGiftCode","")
		},
		onReady() {
			this.getDataNow()
		},
		onShow() {
			this.getcategory()
			this.getchangetab()
			this.gift_list_length = this.add_gift_list.length
			this.getCreateConfig()
			console.log(this.luttery_key)
		},
		methods:{
			getLutteryInfo(){
				let _self = this
				clearInterval(_self.lookVideo_interval)
				uni.request({
					url: util.getUrl("prizedraw/info"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
						prizedraw_id:_self.luttery_id
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							let create_luttery={
									status:0, //0保存 1发布（红包活动需要先保存，支付才能发布）
									prize:{
										type_id:res.data.data.info.type_id,//分类id
										tag_id:res.data.data.info.tag_id,//标签id
										type:_self.page_type,//1抽奖码 2红包
										name:res.data.data.info.name,//标题
										desc:res.data.data.info.desc,//说明
										cover:res.data.data.info.cover,//封面图
										robot_total:0,//机器人总数
										single_robot_min:0,//单次最少增加N个机器人
										single_robot_max:0,//单次最多增加N个机器人
										open_type:res.data.data.info.open_type,//开奖类型(1指定时间 2指定人数 3即开即中)
										open_time:'',//开奖时间（open_type 1、3的时候选择结束时间 ）
										open_num:res.data.data.info.open_num,//开奖人数（open_type 2的时候选择结束时间 ）
										condition_sex:res.data.data.info.condition_sex,//性别限制(0不限 1男 2女)
										condition_token:res.data.data.info.condition_token,//抽奖口令
										content:res.data.data.info.content,//图文内容的内容
										images:res.data.data.info.images,//图片数组 示例：[‘1.png’,’2.jpg’]
										diversion_type:res.data.data.info.diversion_type,//引流类型(1微信号 2公众号 3小程序 4微信群)
										diversion_name:res.data.data.info.diversion_name,//引流名称
										diversion_image:res.data.data.info.diversion_image,//引流图片
										diversion_appid:res.data.data.info.diversion_appid,//引流小程序Appid 当diversion_type=3时可以传这个
										diversion_path:res.data.data.info.diversion_path,//引流小程序路径 当diversion_type=3时可以传这个
									},
									goods:[
										{
											id: _self.edit_type == 1?0:'',
											type:res.data.data.goods[0].type || _self.page_type,//1抽奖码 2普通红包 3手气红包
											name:res.data.data.goods[0].name || '',//奖品名称 （红包奖品不需要填这个）
											image:res.data.data.goods[0].image || '',//奖品图片 （红包奖品不需要填这个）
											code:res.data.data.goods[0].code || '',//奖品码（一行一个）（红包奖品不需要填这个）
											money:res.data.data.goods[0].money || '',//红包金额
											num:res.data.data.goods[0].num || '',//红包数量
											probability:res.data.data.goods[0].probability || 0,//中奖概率（即开即中的时候 需要设置每个奖项的中奖概率）
										},
									]
								}
							_self.create_luttery.prize = create_luttery.prize
							_self.create_luttery.goods = create_luttery.goods
							console.log("_self.create_luttery.prize",_self.create_luttery.prize)
							console.log("_self.create_luttery.prize",_self.create_luttery.goods)
							_self.prize_image = res.data.data.info.images
							_self.$store.commit("createKey",res.data.data.info.condition_token)
							_self.create_luttery.prize.tag_id = res.data.data.info.tag_id
							_self.create_luttery.prize.tag_id = res.data.data.info.type_id
							_self.category_name = res.data.data.info.type_name
							_self.top_iamge = res.data.data.info.cover
							_self.tab_name = res.data.data.info.tag_name
							let data = {
								diversion_type:res.data.data.info.diversion_type,
								diversion_name:res.data.data.info.diversion_name,
								diversion_image:res.data.data.info.diversion_image,
								diversion_appid:res.data.data.info.diversion_appid,
								diversion_path:res.data.data.info.diversion_path,
							}
							_self.$store.commit("giftIndex",0)
							_self.$store.commit("saveDiversion",data)
							_self.getCreateConfig()
						}else{
							if(res.data.code == 500){
								uni.navigateTo({
									url:'../../../pages/login/login'
								})
							}
						}
					},
				});
			},
			getCreateConfig(){
				console.log('this.$store.state.gift_code',this.$store.state.gift_code)
				if(this.$store.state.gift_code != "") {
					this.create_luttery.goods[this.$store.state.gift_index].code = this.$store.state.gift_code
				}else {
					this.create_luttery.goods[this.$store.state.gift_index].code = ''
				}
				if(this.$store.state.create_key == "nokey"){
					this.luttery_key = ''
				}else{
					this.luttery_key = this.$store.state.create_key
					this.create_luttery.prize.condition_token = this.$store.state.create_key
				}
				this.create_luttery.prize.type = this.page_type
				this.create_luttery.prize.diversion_type = this.$store.state.diversion.diversion_type
				this.create_luttery.prize.diversion_name = this.$store.state.diversion.diversion_name
				this.create_luttery.prize.diversion_image = this.$store.state.diversion.diversion_image
				this.create_luttery.prize.diversion_appid = this.$store.state.diversion.diversion_appid
				this.create_luttery.prize.diversion_path = this.$store.state.diversion.diversion_path
			},
			beforeNowCreate(type){
				if(this.create_luttery.prize.cover ==""){
					uni.showToast({
						 title:'请上传封面图！',
						 icon:'none'
					})
				}else if(this.create_luttery.prize.type_id ==0){
					uni.showToast({
						 title:'请选择分类！',
						 icon:'none'
					})
				}else if(this.create_luttery.prize.tag_id ==0){
					uni.showToast({
						 title:'请选择标签！',
						 icon:'none'
					})
				}else if(this.create_luttery.prize.name ==""){
					uni.showToast({
						 title:'请输入标题！',
						 icon:'none'
					})
				}else if(this.create_luttery.prize.open_time ==""){
					uni.showToast({
						 title:'请填写开奖时间！',
						 icon:'none'
					})
				}else{
					this.nowCreate(type)
				}
			},
			nowCreate(type){
				let _self = this
				_self.create_luttery.status = type
				if(_self.edit_type == 1){
					_self.create_luttery.prize.id = _self.luttery_id
					for(let key in _self.create_luttery.goods){
						_self.create_luttery.goods[key]
					}
				}
				_self.edit_type == 0 ? '': _self.luttery_id
				console.log(_self.create_luttery)
				console.log(JSON.stringify(_self.create_luttery.prize))
				console.log(JSON.stringify(_self.create_luttery.goods))
				uni.request({
					url: util.getUrl("prizedraw/add"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
						status: type,
						prize: JSON.stringify(_self.create_luttery.prize),
						goods: JSON.stringify(_self.create_luttery.goods) ,
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							if(type == 1 && _self.page_type == 2){
								_self.toPay(res.data.data.id)
							}else{
								uni.showToast({
									title: _self.page_type == 2? '保存成功！':'发起成功',
									icon:'success'
								})
								setTimeout(()=>{
									uni.reLaunch({
										url:'../luttery/index'
									})
								},2500)
							}
							
						}else{
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
						}
					},
				});
			},
			toPay(id){
				let _self = this
				uni.request({
					url: util.getUrl("prizedraw/pay"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
						prizedraw_id:id
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							uni.requestPayment({
								provider:'wxpay',
								timeStamp:res.data.data.timeStamp,
								nonceStr:res.data.data.nonceStr,
								package:res.data.data.package,
								signType:res.data.data.signType,
								paySign:res.data.data.sign,
								success: (res) => {
									uni.showToast({
										title:'创建成功！',
										icon:'success'
									}) 
									setTimeout(()=>{
										uni.reLaunch({
											url:'../luttery/index'
										})
									},3000)
								},
								fail: (e) => {
									console.log(e)
									uni.showToast({
										title:'支付取消，创建失败',
										icon:'none'
									})
								}
							}) 
						}else{
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
						}
					},
				});
			},
			getDataNow(){
				let myDate = new Date();
				let year = myDate.getFullYear();
				let month = myDate.getMonth();
				let day = myDate.getDate();
				let hour = myDate.getHours();
				let minute = myDate.getMinutes();
				let second = myDate.getSeconds();
				this.default_time = `${year}-${month+1}-${day} ${hour}:${minute}:${second}`
				console.log(this.default_time)
			},
			changeTime(e){
				let _self = this
				_self.create_luttery.prize.open_time = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}:${e.second}`
				console.log(_self.create_luttery.prize.open_time)
				_self.$refs.upickerPopup.close()
			},
			changeMoneyType(index,is_spell){
				this.create_luttery.goods[index].type = is_spell
			},
			getcategory(){
				let _self = this
				uni.request({
					url: util.getUrl("prizedraw/category"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							_self.category_list = res.data.data
						}else{
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
						}
					},
				});
			},
			getchangetab(){
				let _self = this
				uni.request({
					url: util.getUrl("prizedraw/tag"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							_self.tab_list = res.data.data
						}else{
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
						}
					},
				});
			},
			changeCategory(id,name){
				this.create_luttery.prize.type_id = id
				this.category_name = name
				console.log(this.create_luttery.prize.type_id,this.category_name)
				this.$refs.openCategoryPopup.close()
			},
			changetab(id,name){
				this.create_luttery.prize.tag_id = id
				this.tab_name = name
				console.log(this.create_luttery.prize.tag_id,this.tab_name)
				this.$refs.opentabPopup.close()
			},
			changeUserCardStatus(type){
				this.is_usercard = type
				this.$refs.openUserCardPopup.close()
			},
			goToAddFans(){
				uni.navigateTo({
					url:'../startLuttery/addFans'
				})
			},
			goToAddKey(index){
				this.$store.commit("giftIndex",index)
				this.$store.commit("saveCreateLutteryGoods",this.create_luttery.goods)
				uni.navigateTo({
					url:'../startLuttery/addGiftKey'
				})
			},
			addGiftClick(){
				if(this.edit_type == 1){
					this.goods_id +=1 
				}else{
					this.goods_id = ""
				}
				this.create_luttery.goods.push({
					id:this.goods_id,
					type:1,//1抽奖码 2普通红包 3手气红包
					name:"",//奖品名称 （红包奖品不需要填这个）
					image:'',//奖品图片 （红包奖品不需要填这个）
					code:'',//奖品码（一行一个）（红包奖品不需要填这个）
					money:'',//红包金额
					num:'',//红包数量
					probability:0,//中奖概率（即开即中的时候 需要设置每个奖项的中奖概率）
				})
				this.gift_list_length = this.create_luttery.goods.length
				this.number_chanese = this.znTextChinese(this.gift_list_length+1)
				console.log(this.number_chanese)
			},
			znTextChinese(num){
				//完成将 toChineseNum， 可以将数字转换成中文大写的表示，处理到万级别，例如 toChineseNum(12345)，返回 一万二千三百四十五。
				let changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']; //changeNum[0] = "零"
				let unit = ["", "十", "百", "千", "万"];
				num = parseInt(num);
				let getWan = (temp) => {
					let strArr = temp.toString().split("").reverse();
					let newNum = "";
					for (var i = 0; i < strArr.length; i++) {
						newNum = (i == 0 && strArr[i] == 0 ? "" : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? "" : changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum;
					}
					return newNum;
				}
				let overWan = Math.floor(num / 10000);
				let noWan = num % 10000;
				if (noWan.toString().length < 4) noWan = "0" + noWan;
				return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
			},
			goToSetKey(){
				uni.navigateTo({
					url:'../startLuttery/lutterySetKey'
				})
			},
			changeSex(type){
				this.sex = type
				this.create_luttery.prize.condition_sex = type
				this.$refs.openSexPopup.close()
			},
			changeCondition(type){
				this.conditions = type
				this.create_luttery.prize.open_type = type
				this.$refs.openConditionPopup.close()
			},
			changeGiftImage(index){
				let _self = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
				    success: function (res) {
						console.log("123",res.tempFilePaths)
						_self.gift_image[index]=res.tempFilePaths[0]
						uni.showLoading({
							mask:true
						})
						uni.uploadFile({
							url: util.getUrl("common/upload"), //仅为示例，非真实的接口地址
							filePath: res.tempFilePaths[0],
							name: 'file',
							formData: {
								name: res.tempFilePaths[0]
							},
							header: {
								'content-type': 'multipart/form-data',
								'Authori-zation':uni.getStorageSync("token")
							},
							success: (uploadFileRes) => {
								let linshi = JSON.parse(uploadFileRes.data)
								_self.create_luttery.goods[index].image = '/'+linshi.data
								uni.hideLoading()
							},
							fail: (err) => {
								uni.hideLoading()
								uni.showToast({
									icon: 'none',
									title: err,
									duration: 5000
								})
							}
						});
					}
				});
			},
			changeTitleImage(){
				let _self = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function (res) {
						console.log("123",res.tempFilePaths)
						_self.top_iamge = res.tempFilePaths[0]
						uni.showLoading({
							mask:true
						})
						uni.uploadFile({
							url: util.getUrl("common/upload"), //仅为示例，非真实的接口地址
							filePath: res.tempFilePaths[0],
							name: 'file',
							formData: {
								name: res.tempFilePaths[0]
							},
							header: {
								'content-type': 'multipart/form-data',
								'Authori-zation':uni.getStorageSync("token")
							},
							success: (uploadFileRes) => {
								let linshi = JSON.parse(uploadFileRes.data)
								_self.create_luttery.prize.cover = '/'+linshi.data
								uni.hideLoading()
							},
							fail: (err) => {
								uni.hideLoading()
								uni.showToast({
									icon: 'none',
									title: err,
									duration: 5000
								})
							}
						});
					}
				});
			},
			uploadqucodefunction(){
				let _self = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function (res) {
						console.log("123",res.tempFilePaths)
						_self.prize_image.push(res.tempFilePaths[0])
						uni.showLoading({
							mask:true
						})
						uni.uploadFile({
							url: util.getUrl("common/upload"), //仅为示例，非真实的接口地址
							filePath: res.tempFilePaths[0],
							name: 'file',
							formData: {
								name: res.tempFilePaths[0]
							},
							header: {
								'content-type': 'multipart/form-data',
								'Authori-zation':uni.getStorageSync("token")
							},
							success: (uploadFileRes) => {
								let linshi = JSON.parse(uploadFileRes.data)
								_self.create_luttery.prize.images.push('/'+linshi.data)
								uni.hideLoading()
							},
							fail: (err) => {
								uni.hideLoading()
								uni.showToast({
									icon: 'none',
									title: err,
									duration: 5000
								})
							}
						});
					}
				});
			},
			getRedIndex(index){
				this.red_index = index
				console.log(this.red_index)
			},
			deleteIndexRedMoney(index,item){
				this.create_luttery.goods.splice(index,1)
			},
			addRedMoneyNumber(){
				this.create_luttery.goods.push({
					type:2,//1抽奖码 2普通红包 3手气红包
					name:"",//奖品名称 （红包奖品不需要填这个）
					image:'',//奖品图片 （红包奖品不需要填这个）
					code:'',//奖品码（一行一个）（红包奖品不需要填这个）
					money:'',//红包金额
					num:'',//红包数量
					probability:0,//中奖概率（即开即中的时候 需要设置每个奖项的中奖概率）
				})
			},
		}
	}
</script>

<style lang="scss">
	.bottom-btn{
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 34upx;
		width: 690upx;
		height: 80upx;
		border-radius: 10upx;
	}
	.condition-list{
		display: flex;
		align-items: center;
		flex-direction: column;
		width: 750upx;
		box-sizing: border-box;
		padding: 0 30upx;
		border-radius: 20upx 20upx 0px 0px;
		.item1{
			display: flex;
			align-items: center;
			padding: 36upx 0;
			width: 750upx;
			justify-content: center;
		}
	}
	.condition-item2{
		width: 750upx;
		display: flex;
		align-items: center;
		padding: 36upx 0;
		justify-content: center;
	}
	.publicpopup{
		display: flex;
		align-items: center;
		flex-direction: column;
	}
	.bottom-list{
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.item1{
			width: 330upx;
			height: 79upx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 10upx;
		
		}
	}
	.bottom-text{
		margin-top: 10upx;
		margin-bottom: 40upx;
	}
	.add-image{
		width: 100%;
		display: flex;
		justify-content:flex-start;
		.addimage{
			display: flex;
			flex-direction: column;
			align-items: center;
			.upload-image{
				width: 45upx;
				height: 36upx;
				margin-bottom: 22upx;
			}
		}
	}
	.textarea-class-rule{
		margin-top: 30upx;
		width: 100%;
		height: 200upx;
	}
	.join-index{
		display: flex;
		width: 100%;
		flex-direction: column;
		align-items: center;
		overflow: hidden;
	}
	.title-item{
		display: flex;
		width: 100%;
		align-items: center;
		justify-content: space-between;
		box-sizing: border-box;
		padding: 30upx 0;
		.item-left{
			display: flex;
			align-items: center;
			.next-bload{
				width: 20upx;
				height: 31upx;
				margin-left: 18upx;
			}
		}
	}
	.top-title{
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		box-sizing: border-box;
		padding-bottom: 30upx;
		.show-more{
			width: 31upx;
			height: 20upx;
		}
		.class-show-180{
			transform: rotate(180deg);
		}
		.class-show-0{
			transform: rotate(0deg);
		}
	}
	.textarea-class{
		margin-top: 30upx;
		width: 100%;
		height: 200upx;
	}
	.add-red-money{
		width: 100%;
		text-align: center;
		font-size: 30upx;
		font-weight: 500;
		margin-top: 30upx;
	}
	.red-item-money{
		display: flex;
		width: 100%;
		.item-info{
			display: flex;
			flex-direction: column;
			width: 100%;
			.all-red-number-money{
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 30upx 0;
				.input-class{
					display: flex;
					align-items: center;
					.input-text{
						width: 100upx;
						height: 40upx;
						font-size: 30upx;
						margin-right: 20upx;
						text-align: right;
					}
					.input-text-page2{
						width: 220upx;
						font-size: 30upx;
						text-align: right;
					}
					.input-text-page21{
						font-size: 30upx;
						margin-right: 20upx;
					}
					.page2-image{
						width: 20upx;
						height: 31upx;
					}
				}
				.left-title{
					display: flex;
					align-items: center;
					.text-all{
						margin-right: 21upx;
					}
					.left-icon{
						width: 24upx;
						height: 24upx;
						margin-right: 10upx;
					}
				}
			}
		}
		.delete-image{
			width: 34upx;
			height: 34upx;
			margin-right: 27upx;
			margin-top: 34upx;
		}
	}
	.create-red{
		width: 631upx;
		height: 300upx;
		position: relative;
		display: flex;
		align-items: center;
		justify-content: center;
		.red-image{
			width: 100%;
			height: 100%;
		}
		.change-image-red{
			position: absolute;
			z-index: 3;
			top: 20upx;
			right: 20upx;
			background: rgba(0,0,0,0.5);
			border-radius: 4upx;
			width: 150upx;
			height: 48upx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	.create-view-page2{
		width: 690upx;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 30upx 30upx 0 30upx;
		box-sizing: border-box;
		border-radius: 20upx;
		margin-bottom: 30upx;
	}
	.create-view{
		width: 690upx;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 30upx;
		box-sizing: border-box;
		border-radius: 20upx;
		margin-bottom: 30upx;
	}
	.content{
		display: flex;
		align-items: center;
		flex-direction: column;
		padding: 30upx;
		box-sizing: border-box;
		width: 750upx;
		min-height: 100vh;
	}
</style>
